package com.zzyl.controller;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.*;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DevicePropertyStatusVo;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import com.zzyl.vo.ThingModelPublishedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "设备管理")
@RequestMapping("/iot")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    /**
     * 1.1 从物联网平台同步产品列表
     * */
    @PostMapping("/syncProductList")
    public ResponseResult syncProductList(){
        deviceService.syncProductList();
        return ResponseResult.success();
    }

    @ApiOperation("查询所有产品列表")
    @GetMapping("/allProduct")
    public ResponseResult<List<ProductVo>> allProduct(){
        List<ProductVo> productVoList = deviceService.allProduct();
        return ResponseResult.success(productVoList);
    }

    @ApiOperation("注册设备")
    @PostMapping("/RegisterDevice")
    public ResponseResult registerDevice(@RequestBody DeviceDto dto){
        deviceService.registerDevice(dto);
        return ResponseResult.success();
    }

    @ApiOperation("分页查询设备列表")
    @GetMapping("/pageQueryDevice")
    public ResponseResult<PageResponse<DeviceVo>> pageQuery(DevicePageQueryDto dto){
        PageResponse<DeviceVo> page = deviceService.pageQuery(dto);
        return ResponseResult.success(page);
    }

    @ApiOperation("查询设备详细数据")
    @PostMapping("/QueryDeviceDetail")
    public ResponseResult<DeviceVo> queryDeviceDetail(@RequestBody QueryDeviceDetailDto dto){
        DeviceVo vo = deviceService.queryDeviceDetail(dto);
        return ResponseResult.success(vo);
    }

    @ApiOperation("查询设备功能定义详情")
    @PostMapping("/QueryThingModelPublished")
    public ResponseResult<ThingModelPublishedVo> queryThingModelPublished(@RequestBody QueryThingModelPublishedDto dto){
        ThingModelPublishedVo thingModelPublishedVo = deviceService.queryThingModelPublished(dto);
        return ResponseResult.success(thingModelPublishedVo);
    }

    @ApiOperation("修改设备备注名称")
    @PostMapping("/UpdateDevice")
    public ResponseResult updateDevice(@RequestBody UpdateDeviceDto dto){
        deviceService.updateDevice(dto);
        return ResponseResult.success();
    }

    @ApiOperation("删除设备")
    @DeleteMapping("/DeleteDevice")
    public ResponseResult deleteDevice(@RequestBody DeleteDeviceDto dto){
        deviceService.deleteDevice(dto);
        return ResponseResult.success();
    }

    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation("查询指定设备的物模型运行状态")
    public ResponseResult<DevicePropertyStatusVo> queryDevicePropertyStatus(@RequestBody GivenDevicePhysicalModelDto dto){
        DevicePropertyStatusVo devicePropertyStatusVo = deviceService.queryDevicePropertyStatus(dto);
        return ResponseResult.success(devicePropertyStatusVo);
    }
}